<template>
  <div>
    <input placeholder="输入关键字搜索" v-model="data" />
    <table class="my-table">
      <thead>
        <tr>
          <th>就诊日期</th>
          <th>医生姓名</th>
          <th>诊断结果</th>
          <th>处方信息</th>
          <th>操作</th>
        </tr>
      </thead>
      <MyTbody
        v-for="item in (this.data.length ? renderData : list)"
        :key="item.doctor"
        :time="item.time"
        :doctor="item.doctor"
        :pathology="item.pathology"
        :state="item.state"
        :details="item.details"
      ></MyTbody>
    </table>
  </div>
</template>
<script>
import MyTbody from './components/MyTbody.vue'
export default {
  components: {
    MyTbody,
  },
  data() {
    return {
      list: [
        {
          time: '2020-12-12',
          doctor: '章三',
          pathology: '感冒',
          state: '正常',
          details: '详情',
        },
        {
          time: '2021-1-12',
          doctor: '李四',
          pathology: '发烧',
          state: '正常',
          details: '详情',
        },
        {
          time: '2022-2-12',
          doctor: '王五',
          pathology: '流感',
          state: '正常',
          details: '详情',
        },
      ],

      data: '',
      renderData: [],
    }
  },

  watch: {
    data: {
      handler(newValue) {
        this.renderData = this.list.filter(
          (item) =>
            item.time === newValue ||
            item.doctor === newValue ||
            item.pathology === newValue
        )
      },
    },
  },
}
</script>
<style>
.my-table {
  border-collapse: collapse;
  width: 100%;
}

.my-table td,
.my-table th {
  border: 1px solid #ddd;
  padding: 8px;
  text-align: left;
}

.my-table th {
  background-color: #f2f2f2;
}
</style>
